import { Component, OnInit } from '@angular/core';
import {Hero} from "../mock-heroes";
import {HeroServiceService} from "../hero-service.service";

@Component({
  selector: 'app-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css'],
  providers:[HeroServiceService]
})
export class HeroesComponent implements OnInit {
  title = 'my heros';
  heros:Hero[];
  selectedHero:Hero;

  getHeros():void{
    this.heroService.getHeros().then(heros=> this.heros = heros);
  }

  constructor(private heroService: HeroServiceService) {
  }

  onSelect(hero:Hero):void{
    this.selectedHero = hero;
  }

  ngOnInit():void{
    this.getHeros();
  }

}
